package com.breaktian.assemble.utils;



import android.content.Context;
import android.content.SharedPreferences;

import com.breaktian.assemble.AppGlobal;


/**
 * Created by breaktian on 2016/6/23.
 * shareprefence
 */
public class PrefUtil {
	/**
	 * 默认的sp文件
	 */
	public static final String SP_NAME_DEFAULT = "sp_default";
	public static final String SP_NAME_VIDEO_LEVEL = "sp_name_video_level";
	public static final String SP_KEY_ORDERLIST_SELECT = "orderlist_select";
	public static final String SP_KEY_UPDATE_MASTER_VERSION_START_TIME = "sp_key_update_master_version_start_time";
	/**
	 * user信息
	 * */
	public static final String SP_NAME_USER = "sp_user";
	public static final String SP_KEY_USER_TOKEN = "token";
	public static final String SP_KEY_USER_USERID = "userid";
	public static final String SP_KEY_USER_PHONE = "phone";
	public static final String SP_KEY_USER_NAME_CACHE = "name_cache";
	public static final String SP_KEY_USER_NAME = "name";
	public static final String SP_KEY_USER_PASS = "pass";
	public static final String SP_KEY_USER_MASTERID = "masterId";
	public static final String SP_KEY_USER_MASTERNAME = "masterName";
	public static final String SP_KEY_USER_HEADIMG_PATH = "headimgpath";

	/**
	 * cache信息
	 * */
	public static final String SP_NAME_CACHE = "sp_cache";
	public static final String SP_KEY_CACHE_PHONE = "cache_phone";
	public static final String SP_KEY_CACHE_PASSWORD = "cache_password";
	/**
	 * 通知设置
	 * */
	public static final String SOUNDSET = "sp_soundset";
	public static final String VIBRATESET = "sp_vibrateset";
	public static final String HOMEGUIDE = "home_guide";

	/**
	 * 视频流量设置
	 * */
	public static final String SP_KEY_NETWORK_WIFI_REMIND = "network_wifi_remind";
	public static final String SP_KEY_FLOW_MAX_NUM = "flow_max_num";

	public static void write(String spName, String key, String value) {
		SharedPreferences sharedPreferences = AppGlobal.getContext()
				.getSharedPreferences(spName, Context.MODE_PRIVATE);
		sharedPreferences.edit().putString(key, value).commit();
	}


	public static void write(String spName, String key, int value) {
		SharedPreferences sharedPreferences = AppGlobal.getContext()
				.getSharedPreferences(spName, Context.MODE_PRIVATE);
		sharedPreferences.edit().putInt(key, value).commit();
	}


	public static void write(String spName, String key, long value) {
		SharedPreferences sharedPreferences = AppGlobal.getContext()
				.getSharedPreferences(spName, Context.MODE_PRIVATE);
		sharedPreferences.edit().putLong(key, value).commit();
	}

	public static void write(String spName, String key, float value) {
		SharedPreferences sharedPreferences = AppGlobal.getContext()
				.getSharedPreferences(spName, Context.MODE_PRIVATE);
		sharedPreferences.edit().putFloat(key, value).commit();
	}


	public static void write(String spName, String key, boolean value) {
		SharedPreferences sharedPreferences = AppGlobal.getContext()
				.getSharedPreferences(spName, Context.MODE_PRIVATE);
		sharedPreferences.edit().putBoolean(key, value).commit();
	}

	public static float read(String spName, String key, float defValue) {
		SharedPreferences sharedPreferences = AppGlobal.getContext()
				.getSharedPreferences(spName, Context.MODE_PRIVATE);
		return sharedPreferences.getFloat(key, defValue);
	}

	public static boolean read(String spName, String key, boolean defValue) {
		SharedPreferences sharedPreferences = AppGlobal.getContext()
				.getSharedPreferences(spName, Context.MODE_PRIVATE);
		return sharedPreferences.getBoolean(key, defValue);
	}

	public static int read(String spName, String key, int defValue) {
		SharedPreferences sharedPreferences = AppGlobal.getContext()
				.getSharedPreferences(spName, Context.MODE_PRIVATE);
		return sharedPreferences.getInt(key, defValue);
	}


	public static String read(String spName, String key, String defValue) {
		SharedPreferences sharedPreferences = AppGlobal.getContext()
				.getSharedPreferences(spName, Context.MODE_PRIVATE);
		return sharedPreferences.getString(key, defValue);
	}

	public static long read(String spName, String key, long defValue) {
		SharedPreferences sharedPreferences = AppGlobal.getContext()
				.getSharedPreferences(spName, Context.MODE_PRIVATE);
		return sharedPreferences.getLong(key, defValue);
	}


	public static void clear(String spName) {
		SharedPreferences sharedPreferences = AppGlobal.getContext()
				.getSharedPreferences(spName, Context.MODE_PRIVATE);
		sharedPreferences.edit().clear().commit();
	}


	public static void clear(String spName, String key) {
        SharedPreferences sharedPreferences = AppGlobal.getContext().getSharedPreferences(
                spName,
				Context.MODE_PRIVATE);
		sharedPreferences.edit().remove(key).commit();
	}

}
